home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / 68hc11 / smallc11.arc / CC22.C < prev    next >
Text File  |  1988-05-27  |  4KB  |  222 lines

  1. extern int showcode;
  2.  
  3. ifline()  {
  4.    while(1)  {
  5.       inline();
  6.     if(showcode)
  7.     {
  8.             printf("*%s\n",line);
  9.     }
  10.       if(eof) return;
  11.       if(match("#ifdef"))  {
  12.      ++iflevel;
  13.      if(skiplevel) continue;
  14.      blanks();
  15.      if(findmac(lptr)==0)
  16.         skiplevel=iflevel;
  17.      continue;
  18.      }
  19.       if(match("#ifndef"))  {
  20.      ++iflevel;
  21.      if(skiplevel) continue;
  22.      blanks();
  23.      if(findmac(lptr))
  24.         skiplevel=iflevel;
  25.      continue;
  26.      }
  27.       if(match("#else"))  {
  28.      if(iflevel)  {
  29.         if(skiplevel==iflevel) skiplevel=0;
  30.         else if(skiplevel==0) skiplevel=iflevel;
  31.         }
  32.      else noiferr();
  33.      continue;
  34.      }
  35.       if(match("#endif"))  {
  36.      if(iflevel)  {
  37.         if(skiplevel==iflevel) skiplevel=0;
  38.         --iflevel;
  39.         }
  40.      else noiferr();
  41.      continue;
  42.      }
  43.       if(skiplevel) continue;
  44.       if(listfp)  {
  45.      if(listfp==output) putchar(';');
  46.      printf("%s\n",line);
  47.      }
  48.       if(ch==0) continue;
  49.       break;
  50.       }
  51.    }
  52.  
  53. preprocess() {
  54.   int k;
  55.   char c;
  56.   if(ccode) {
  57.     line=mline;
  58.     ifline();
  59. /*  putchar('*');
  60.     while(*line!= 0) putchar(*line++);
  61.     putchar('\n');      */
  62.     line=mline;
  63.     if(eof) return;
  64.     }
  65.   else {
  66.     line=pline;
  67.     inline();
  68.     return;
  69.     }
  70.   pptr = -1;
  71.   while(ch) {
  72.     if(white()) {
  73.       keepch(' ');
  74.       while(white()) gch();
  75.       }
  76.     else if(ch=='"') {
  77.       keepch(ch);
  78.       gch();
  79.       while((ch!='"')|((*(lptr-1)==92)&(*(lptr-2)!=92))) {
  80.     if(ch==0) {
  81.       error("no quote");
  82.       break;
  83.       }
  84.     keepch(gch());
  85.     }
  86.       gch();
  87.       keepch('"');
  88.       }
  89.     else if(ch==39) {
  90.       keepch(39);
  91.       gch();
  92.       while((ch!=39)|((*(lptr-1)==92)&(*(lptr-2)!=92))) {
  93.     if(ch==0) {
  94.       error("no apostrophe");
  95.       break;
  96.       }
  97.     keepch(gch());
  98.     }
  99.       gch();
  100.       keepch(39);
  101.       }
  102.     else if((ch=='/')&(nch=='*')) {
  103.       bump(2);
  104.       while(((ch=='*')&(nch=='/'))==0) {
  105.     if(ch) bump(1);
  106.     else {
  107.       ifline();
  108.       if(eof) break;
  109.       }
  110.     }
  111.       bump(2);
  112.       }
  113.     else if(an(ch)) {
  114.       k=0;
  115.       while(an(ch)) {
  116.     if(k<NAMEMAX) msname[k++]=ch;
  117.     gch();
  118.     }
  119.       msname[k]=0;
  120.       if(k=findmac(msname)) while(c=macq[k++]) keepch(c);
  121.       else {
  122.     k=0;
  123.     while(c=msname[k++]) keepch(c);
  124.     }
  125.       }
  126.     else keepch(gch());
  127.     }
  128.   if(pptr>=LINEMAX) error("line too long");
  129.   keepch(0);
  130.   line=pline;
  131.   bump(0);
  132.   }
  133.  
  134. addmac() {
  135.   int k;
  136.   if(symname(msname, NO)==0) {
  137.     illname();
  138.     kill();
  139.     return;
  140.     }
  141.   k=0;
  142.   while(putmac(msname[k++]));
  143.   while(white()) gch();
  144.   while(putmac(gch()));
  145.   if(macptr>=MACMAX) {
  146.     printf("**** SMALL-C: macro string queue full ****\n");
  147.     exit(-1);
  148.     }
  149.   }
  150.  
  151. putmac(c)  {
  152.   macq[macptr]=c;
  153.   if(macptr<MACMAX) ++macptr;
  154.   return c;
  155.   }
  156.  
  157. findmac(sname)    char *sname; {
  158. mack=0;
  159. while(mack<macptr)                /* mack is pointer into */
  160.     { if(astreq(sname,macq+mack,NAMEMAX))    /* table of macros.    */
  161.     { while(macq[mack++]);            /* while mack < macptr    */
  162.     return mack;                /* (end of table), search*/
  163.     }
  164.     while(macq[mack++]);
  165.     while(macq[mack++]);
  166.     }
  167. return 0;
  168. }
  169. astreq(str1,str2,len)
  170. char str1[],str2[];int len;
  171. {
  172. int k;
  173.  
  174. k=0;
  175. while (k<len)
  176.     { if ((str1[k])!=(str2[k]))break;
  177.     /*      ** must detect end of symbol table names terminated by
  178.     ** symbol length in binary      */
  179.     if(str1[k] < ' ') break;
  180.     if(str2[k] < ' ') break;
  181.     ++k;
  182.     }
  183. if (an(str1[k]))return 0;
  184. if (an(str2[k]))return 0;
  185. return k;
  186. }
  187.  
  188.  
  189. setstage(before, start) int *before, *start; {
  190.   if((*before=stagenext)==0) stagenext=stage;
  191.   *start=stagenext;
  192.   }
  193.  
  194. clearstage(before, start) char *before, *start; {
  195.   *stagenext=0;
  196.   if(stagenext=before) return;
  197.   if(start) {
  198.     printf("%s",start);
  199.     }
  200.   }
  201.  
  202. nextop(list) char *list; {
  203.   char op[4];
  204.   opindex=0;
  205.   blanks();
  206.   while(1) {
  207.     opsize=0;
  208.     while(*list > ' ') op[opsize++]= *list++;
  209.     op[opsize]=0;
  210.     if(opsize=streq(lptr, op))
  211.       if((*(lptr+opsize) != '=')&
  212.      (*(lptr+opsize) != *(lptr+opsize-1)))
  213.      return 1;
  214.     if(*list) {
  215.       ++list;
  216.       ++opindex;
  217.       }
  218.     else return 0;
  219.     }
  220.   }
  221.  
  222.